package com.gitee.hermer.engine.jars.dependent.redis.config;

import org.apache.commons.lang3.BooleanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import com.gitee.hermer.boot.jee.commons.number.IntegerUtils;
import com.gitee.hermer.boot.jee.commons.number.NumberUtils;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.dependent.dsm.domain.EngineProperties;

@PropertySource(EngineConstant.ENGINE_CONFIG_PROPERTIES_CLASS_PATH)
public class RedisProperties extends EngineProperties{

	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_MAXIDLE)
	private Integer maxIdle;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_MINIDLE)
	private Integer minIdle;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_MAXTOTAL)
	private Integer maxTotal;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_MAXWAITMILLIS)
	private Integer maxWaitMillis;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_TIMEBETWEENEVICTIONRUNSMILLIS)
	private Integer timeBetweenEvictionRunsMillis;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_MINEVICTABLEIDLETIMEMILLIS)
	private Integer minEvictableIdleTimeMillis;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_POOL_TESTONBORROW)
	private Boolean testOnBorrow;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_CONFIG_HOST)
	private String host;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_CONFIG_PORT)
	private Integer port;
	@Value(EngineConstant.PROPERTIES_KEY_ENGINE_CONFIG_REDIS_CONFIG_PASSWORD)
	private String password;
	
	public Integer getMaxIdle() {
		return IntegerUtils.defaultIfZero(maxIdle, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_MAXIDLE);
	}
	public void setMaxIdle(Integer maxIdle) {
		this.maxIdle = maxIdle;
	}
	public Integer getMaxTotal() {
		return IntegerUtils.defaultIfZero(maxTotal, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_MAXTOTAL);
	}
	public void setMaxTotal(Integer maxTotal) {
		this.maxTotal = maxTotal;
	}
	public Integer getMaxWaitMillis() {
		return IntegerUtils.defaultIfZero(maxWaitMillis, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_MAXWAITMILLIS);
	}
	public void setMaxWaitMillis(Integer maxWaitMillis) {
		this.maxWaitMillis = maxWaitMillis;
	}
	public Integer getTimeBetweenEvictionRunsMillis() {
		return IntegerUtils.defaultIfZero(timeBetweenEvictionRunsMillis, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_TIMEBETWEENEVICTIONRUNSMILLIS);
	}
	public void setTimeBetweenEvictionRunsMillis(Integer timeBetweenEvictionRunsMillis) {
		this.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
	}
	public Integer getMinEvictableIdleTimeMillis() {
		return IntegerUtils.defaultIfZero(minEvictableIdleTimeMillis, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_MINEVICTABLEIDLETIMEMILLIS);
	}
	public void setMinEvictableIdleTimeMillis(Integer minEvictableIdleTimeMillis) {
		this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
	}
	public Boolean getTestOnBorrow() {
		return BooleanUtils.toBooleanDefaultIfNull(testOnBorrow, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_TESTONBORROW);
	}
	public void setTestOnBorrow(Boolean testOnBorrow) {
		this.testOnBorrow = testOnBorrow;
	}
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public Integer getPort() {
		return port;
	}
	public void setPort(Integer port) {
		this.port = port;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public Integer getMinIdle() {
		return IntegerUtils.defaultIfZero(minIdle, EngineConstant.DEFAULT_VALUES_ENGINE_CONFIG_REDIS_POOL_MINIDLE);
	}
	public void setMinIdle(Integer minIdle) {
		this.minIdle = minIdle;
	}

}
